package controller.api;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;

import common.inter.ServicerStationInter;
import common.inter.StaffStationInter;
import model.EquipmentTypes;
import model.Quipment;
import service.QuipmentService;

public class ApiQuipmentController extends BaseApiController {
	@Inject QuipmentService quipmentService ;

	@Before(ServicerStationInter.class)
	public void list() {
	    Kv kv = getParamKv() ;
	    kv.set("tq.stationId", getStation().getId());
	    Integer pageNumber = getParaToInt("pageNumber", 1);
	    Integer pageSize = getParaToInt("pageSize", 10);
	    set("page", quipmentService.getApiPage( kv , pageNumber, pageSize));
	    set("options", EquipmentTypes.dao.getOptionsList(getStation().getId()));
	    renderJson();
	}
	
	public void options() {
		Long stationId = getParaToLong("stationId");
		renderJson("list" , EquipmentTypes.dao.getOptionsList(stationId));
	}

	@Before(StaffStationInter.class)
	public void save() {
		Quipment quipment = getModel(Quipment.class , "x" , true );
        Ret ret = quipmentService.save(quipment , getStaff() , getStation());
        renderJson(ret);
	}
	
	@Before(StaffStationInter.class)
	public void delete() {
		Long mId = getParaToLong("mId");
		renderJson(quipmentService.delete(mId));
	}
	
}
